package tankwar;

import java.awt.*;
import java.util.*;

public class EnemyBullet extends Bullet{
    public EnemyBullet(String img, int x, int y, Direction direction, GamePanel gamePanel) {
        super(img, x, y, direction, gamePanel);
    }
    public void hitPlayer() {
        Rectangle next=this.getRec();
        ArrayList<Tank> tanks=this.gamePanel.tankList;
        for(Tank tank:tanks) {
            if(tank.getRec().intersects(next)){
                System.out.println("hit tank");
                tank.alive=false;
                this.gamePanel.tankList.remove(tank);
                this.gamePanel.removeList.add(this);
                this.gamePanel.blastList.add(new BlastObj(tank.x-34, tank.y-14));
                break;
            }
        }
    }
    public void paintSelf(Graphics g) {
        g.drawImage(img,x,y,null);
        go();
        hitPlayer();
    }

    @Override
    public Rectangle getRec() {
        return new Rectangle(x, y, width, height);
    }
}
